Conditions | 3 |
Paths | 1 |
Total Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import deepEqual from 'deep-equal'; |
||
70 | export function shouldRowUpdate(nextProps) { |
||
71 | let result = true; |
||
72 | |||
73 | // unique key created by setData action/reducer |
||
74 | const key = nextProps.row._key; |
||
75 | |||
76 | const isSelected = rows => Boolean(rows && rows[key]); |
||
77 | |||
78 | const isMenuShown = rows => Boolean(rows && rows[key]); |
||
79 | |||
80 | const isEdited = editorState => Boolean( |
||
81 | editorState |
||
82 | && editorState.row |
||
83 | && editorState.row.rowIndex === nextProps.index |
||
84 | && editorState.row.values |
||
85 | ); |
||
86 | |||
87 | const limitedNextProps = { |
||
88 | columns: slimColumn(nextProps.columns), |
||
89 | isEdited: isEdited(nextProps.editorState), |
||
90 | currentValues: isEdited(nextProps.editorState) |
||
91 | ? nextProps.editorState |
||
92 | : null, |
||
93 | isMenuShown: isMenuShown(nextProps.menuState), |
||
94 | row: nextProps.row, |
||
95 | index: nextProps.index, |
||
96 | isSelected: isSelected(nextProps.selectedRows), |
||
97 | isDragging: nextProps.isDragging |
||
98 | }; |
||
99 | |||
100 | const limitedProps = { |
||
101 | columns: this.previousColumns, |
||
102 | isEdited: isEdited(this.props.editorState), |
||
103 | currentValues: isEdited(nextProps.editorState) |
||
104 | ? this.props.editorState |
||
105 | : null, |
||
106 | isMenuShown: isMenuShown(this.props.menuState), |
||
107 | row: this.props.row, |
||
108 | index: this.props.index, |
||
109 | isSelected: isSelected(this.props.selectedRows), |
||
110 | isDragging: this.props.isDragging |
||
111 | }; |
||
112 | |||
113 | this.previousColumns = slimColumn(this.props.columns.slice()); |
||
114 | |||
115 | result = ( |
||
116 | !deepEqual(limitedNextProps, limitedProps) |
||
117 | ); |
||
118 | |||
119 | return result; |
||
120 | } |
||
121 | |||
130 |